package day14.com.zhiyou100;


import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;

// 准备一个测试类
class Main {

    public static void main(String[] args) {
        // 准备一个Set容器
        Set<Student> studentSet = new TreeSet<>();
        studentSet.add(new Student("001","张三1",90));// 地址值
        studentSet.add(new Student("003","张三",80));
        studentSet.add(new Student("008","张三8",100));
        studentSet.add(new Student("005","张三5",70));
        studentSet.add(new Student("004","张三7",50));
        System.out.println(studentSet);// 排序
    }
}

public class Student{

    private String id;
    private String name;

    Integer score;

    public Student(String id, String name, Integer score) {
        this.id = id;
        this.name = name;
        this.score = score;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Objects.equals(id, student.id) && Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name);
    }

    @Override
    public String toString() {
        return "Student{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", score=" + score +
                '}';
    }

    public Student() {
    }

    public Student(String id, String name) {
        this.id = id;
        this.name = name;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
/*
   @Override
    public int compareTo(Student o) {
        return this.score - o.score;//this.score - o.score
    }*/

}
